<?php

require_once('./configure.php');
global $cfg;
/* обработчик для кнопок на форме комментария */
if (isset($_POST['comment_button'])) {
    //comment action
    $htmlgen = new HTMLGenerate();
    $hiddenmsgsinput = '<input type="hidden" value="' . $_REQUEST['msgid'] . '" name="msgid"/>';
    include($cfg->dirroot . '/views/addcomment.html');
} else if (isset($_POST['edit_button'])) {
    //edit action
    
    $client_db = new $cfg->dbmethod;
    $message = $client_db->getMessageByID($_REQUEST['msgid']);
    
    $inputname = '<input name="author" type="text" id="name" value="' . "${message['author']}" . '"/>';
    $inputtext = '<textarea name="message" id="message">' . "${message['text']}" . '</textarea>' ;
    $submittype = '<input type="submit" name="upd_msg_btn" value="Update" />';
    
    $hiddenmsgsinput = '<input type="hidden" value="' . $_REQUEST['msgid'] . '" name="msgid"/>' . "\n";
    $hiddeninput = $hiddenmsgsinput;
    
    include ($cfg->dirroot . '/views/edit_text.html');

} else if (isset($_POST['delete_button'])) {
    //delete action
    $client_db = new $cfg->dbmethod;
    $success = $client_db->deleteMessage($_REQUEST['msgid']);

    if ($success) $statusmsg = "Message No. ${_REQUEST['msgid']} successfully deleted"; 
    else $statusmsg = "Error: Message No. ${_REQUEST['msgid']} wasn't deleted";
    $htmlgen = new HTMLGenerate();
    include ($cfg->dirroot . '/views/main.html');
}


